package com.mobeedom.android.justinstalled.db;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import android.util.Log;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.DatabaseTable;
import com.j256.ormlite.table.TableUtils;

import static com.mobeedom.android.justinstalled.AppSingleton.LOG_TAG;

@DatabaseTable(tableName = "dbversion")
public class DbVersion {

	private static transient List<String> allSql = new ArrayList<String>();
	public static transient final int VERSION = 10;

	@DatabaseField(id = true)
	private Long id;

	@DatabaseField
	private int version;

	public DbVersion(Long id, int version) {
		this.id = id;
		this.version = version;
	}

	public DbVersion() {
		super();
	}

	public static synchronized List<String> getAlters(Integer oldVersion, ConnectionSource connectionSource)
			throws SQLException {
		allSql.clear();
		switch (oldVersion) {
		case 0:
		case 1:
//			allSql.add("alter table recordinginfo add dateRec VARCHAR(15)");
		}
		if (oldVersion != VERSION) {
			allSql.add("update dbversion set version = " + VERSION);
			Log.d(LOG_TAG, "Istruzioni SQL eseguite (oldversion = " + oldVersion + " newversion = " + VERSION + ")");
			for (String istr : allSql) {
				Log.d(LOG_TAG, "\t" + istr);
			}
		}
		return allSql;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public int getVersion() {
		return version;
	}

	public void setVersion(int version) {
		this.version = version;
	}
}